<div>
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-head" style="padding: 8px">
                <div class="col-md-1 align-left">
                    <select name="type" id="type" class="form-control select-option col-sm-12 select-opacity selectEdit select-border">
                        <option value="1" <?php echo $this->type == '1' ? 'selected' : '';?>>周排行</option>
                        <option value="2" <?php echo $this->type == '2' ? 'selected' : '';?>>总排行</option>
                    </select>
                </div>
                <div class="col-md-1 align-left" id="s2" style=" <?php echo $this->type == '2' ? 'display:none' : '';?>">
                    <select name="week_type" id="week_type" class="form-control select-option col-sm-12 select-opacity selectEdit select-border">
                        <option value="1" <?php echo $this->week_type == '1' ? 'selected' : '';?>>第一周</option>
                        <option value="2" <?php echo $this->week_type == '2' ? 'selected' : '';?>>第二周</option>
                        <option value="3" <?php echo $this->week_type == '3' ? 'selected' : '';?>>第三周</option>
                        <option value="4" <?php echo $this->week_type == '4' ? 'selected' : '';?>>第四周</option>
                    </select>
                </div>
            </div>
            <div style="clear: both"></div>
            <div class="panel-body">
                <section id="no-more-tables">
                    <table class="table table-bordered table-striped table-condensed cf">
                        <thead class="cf">
                        <tr>
                            <td>序号</td>
                            <td>用户昵称</td>
                            <td>排名</td>
                            <td>积分</td>
                            <td>中奖奖品</td>
                            <td>奖品图片</td>
                            <td>时间</td>
                            <td>用户地址</td>
                            <td>物流单号</td>
                            <td>操作</td>
                        </tr>
                        </thead>
                        <tbody>
                        <?php
                            $i = ($this->now - 1) * $this->size+1;
                            if(!empty($this->list)){
                                foreach ($this->list as $info) { ?>
                                    <tr>
                                        <td data-title="序号"><?php echo $i++; ?></td>
                                        <td data-title="用户昵称"><?php echo $info['nickname']; ?></td>
                                        <td data-title="排名">第 <span class="red"><?php echo $info['user_sort']?></span> 名</td>
                                        <td data-title="积分"><?php echo $info['user_score']?></td>
                                        <td data-title="中奖奖品"><?php echo $info['name']?></td>
                                        <td data-title="奖品图片">
                                            <div class="img-border" style="text-align: center">
                                                <img src="<?php echo $info['portrait'] ?>" width="50"/>
                                            </div>
                                        </td>
                                        <td data-title="时间"><?php echo $info['insert_time']?></td>
                                        <td>
                                            <?php if ($info['ship_username'] == ''){?>
                                                待完善
                                            <?php }else{?>
                                                <a data-toggle="modal" href="#myModal"
                                                   province="<?php echo $info['province'] ?>"
                                                   city="<?php echo $info['city'] ?>"
                                                   area="<?php echo $info['area'] ?>"
                                                   address="<?php echo $info['address'] ?>"
                                                   ship_username="<?php echo $info['ship_username'] ?>"
                                                   ship_mobile="<?php echo $info['ship_mobile'] ?>"
                                                   onclick="check_address(this)"
                                                  >查看</a>
                                            <?php }?>
                                        </td>
                                        <td><?php echo $info['status'] == 1 ? $info['logistics_num'] : '--' ?></td>
                                        <td>
                                            <?php if ($info['status'] == 1){?>
                                                已发货
                                            <?php }else{?>
                                                <a data-toggle="modal" href="#myModal1"
                                                   data-id="<?php echo $info['id']?>"
                                                   onclick="shipments(this)"
                                                >发货</a>
                                            <?php }?>
                                        </td>
                                    </tr>
                            <?php }}?>
                        </tbody>
                    </table>
                    <?php echo $this->page ?>
                </section>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div style="background-color:#28a8b9;padding:5px 0;text-align:center;color:white">
                <h5>用户地址信息</h5>
            </div>
            <div class="modal-body">
                <div class="panel-body">
                    <div class="form-group" style="line-height: 38px;">
                        <label class="col-lg-3 col-sm-3 control-label">收货人名称：</label>
                        <div class="col-lg-4">
                            <input type="text" class="form-control" value="" id="ship_username"  disabled>
                        </div>
                    </div>
                    <div style="clear:both;"></div>
                    <div class="form-group" style="line-height: 38px;">
                        <label class="col-lg-3 col-sm-3 control-label">收货人电话：</label>
                        <div class="col-lg-4">
                            <input type="text"  class="form-control" value="" id="ship_mobile"  disabled>
                        </div>
                    </div>
                    <div style="clear:both;"></div>
                    <div class="form-group" style="line-height: 38px;">
                        <label class="col-lg-3 col-sm-3 control-label">收货人地址：</label>
                        <div class="col-lg-8">
                            <input type="text"  class="form-control" value="" id="ship_address"  disabled>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer" style="text-align: center;">
                <button class="btn btn-info " class="close" type="button" data-dismiss="modal"  style="margin-left: 50px;">取消</button>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div style="background-color:#28a8b9;padding:5px 0;text-align:center;color:white">
                <h5>发货物流</h5>
            </div>
            <div class="modal-body">
                <div class="panel-body">
                    <input type="hidden" id="rank_id" value="">
                    <div class="form-group" style="line-height: 38px;">
                        <label class="col-lg-3 col-sm-3 control-label">物流单号：</label>
                        <div class="col-lg-8">
                            <input type="text" class="form-control" value="" id="logistics_num" placeholder="请填写物流单号">
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer" style="text-align: center;">
                <button class="btn btn-success sure-save" type="button" style="background-color:#28a8b9;" onclick="saveLogistics(this)">确认</button>
                <button class="btn btn-info " class="close" type="button" data-dismiss="modal"  style="margin-left: 50px;">取消</button>
            </div>
        </div>
    </div>
</div>

<script>
    /* 切换选择排行*/
    $("#type").change(function () {
        var type = $(this).val();
        var week_type = $("#week_type").val();
        if(type == '1'){
            $("#s2").show();
           if(week_type == ''){
               layer.msg('请选择第几周积分中奖排行');
               return;
           }
           window.location.href = '/score/user?type=' + type + '&week_type='+week_type;
        }else{
            $("#s2").hide();
            window.location.href = '/score/user?type=' + type;
        }
    });
    $("#week_type").change(function () {
        var week_type = $("#week_type").val();
        window.location.href = '/score/user?type=1&week_type='+week_type;
    });

    function check_address(el) {
        var province = $(el).attr('province');
        var city = $(el).attr('city');
        var area = $(el).attr('area');
        var address = $(el).attr('address');
        var ship_username = $(el).attr('ship_username');
        var ship_mobile = $(el).attr('ship_mobile');
        $("#ship_username").val(ship_username);
        $("#ship_mobile").val(ship_mobile);
        $("#ship_address").val(province+city+area+address);
    }
    
    function shipments(el) {
        var rank_id = $(el).attr('data-id');
        $("#rank_id").val(rank_id);
    }
    function saveLogistics() {
        var id =  $("#rank_id").val();
        var logistics_num = $("#logistics_num").val();
        layer.confirm('确认发货吗？', function () {
            $.ajax({
                url  : '/score/add-logistics',
                type : 'post',
                data : {
                    id:id,
                    logistics_num:logistics_num
                },
                dataType : 'json',
                success : function (msg) {
                    if (msg.code === 200) {
                        layer.alert(msg.message);
                    } else{
                        layer.alert(msg.message);
                    }
                    window.location.reload();
                }
            });
        });
    }
</script>